package com.zxy.ziems.server.energy.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zxy.ziems.server.board.pojo.vo.DosageVo;
import com.zxy.ziems.server.domain.DeviceMeasureData;
import com.zxy.ziems.server.energy.pojo.dto.DeviceDataTypeDTO;
import com.zxy.ziems.server.energy.pojo.entity.DeviceMeasureDataDayEntity;
import com.zxy.ziems.server.energy.pojo.param.DeviceMeasureDataPageParam;
import com.zxy.ziems.server.mybatis.core.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;

@Mapper
public interface DeviceMeasureDataDayMapper extends BaseMapperX<DeviceMeasureDataDayEntity> {


    /**
     * 类型汇总top5
     *
     * @param parentClassifyId
     * @param dataTypeId
     * @param date
     * @return
     */
    List<DosageVo> top5Sum(@Param("classifyId") String parentClassifyId, @Param("dataTypeId") String dataTypeId,
                           @Param("date") LocalDate date, @Param("limit") Integer limit);

    /**
     * 类汇总
     * @param parentClassifyId
     * @param dataTypeId
     * @param startDate
     * @param endDate
     * @return
     */
    BigDecimal classifySum(@Param("classifyId") String parentClassifyId, @Param("dataTypeId") String dataTypeId,
                           @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate);

    /**
     * 按天进行汇总统计
     * @param classifyIds 分类ID集
     * @param dataTypeId
     * @param startDate
     * @param endDate
     * @return
     */
    List<DosageVo> sumByDateTypeAndClassifyIds(@Param("classifyIds") List<String> classifyIds, @Param("dataTypeId") String dataTypeId,
                          @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate, @Param("dateFormat") String dateFormat);
    /**
     * 根据日期类型统计
     * @param parentClassifyId 父类ID
     * @param dataTypeId
     * @param startDate
     * @param endDate
     * @param dateFormat 使用mysql的格式
     * @return
     */
    List<DosageVo> sumByDateType(@Param("classifyId") String parentClassifyId, @Param("dataTypeId") String dataTypeId,
                          @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate, @Param("dateFormat") String dateFormat);

    /**
     *
     * @param startDate
     * @param endDate
     * @param classifyIds
     * @param format
     * @return
     */
    List<DosageVo> classTrend(@Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate,
                              @Param("classifyIds") List<String> classifyIds, @Param("format") String format);

    /**
     * 批量保存列表（相同时间相同设备相同属性会覆盖更新）
     *
     * @param list
     */
    void batchSaveEntityList(List<DeviceMeasureDataDayEntity> list);

    /**
     * 设备属性增量和
     * @param startDate
     * @param endDate
     * @param deviceIds
     * @param format
     * @return
     */
    List<DeviceDataTypeDTO> deviceSum(@Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate, @Param("deviceIds") Set<String> deviceIds, @Param("format") String format);

    /**
     * 批量删除
     * @param deviceIds
     * @param date
     */
    void batchDeleteByIdDate(@Param("deviceIds")List<String> deviceIds,@Param("date") String date);



    /* 分页查询
     * @param page
     * @param param
     * @return
     */
    IPage<DeviceMeasureDataDayEntity> queryPageListByDeviceId(@Param("page") IPage<DeviceMeasureDataDayEntity> page,
                                                              @Param("startDate") LocalDate startDate,
                                                              @Param("endDate") LocalDate endDate,
                                                              @Param("deviceIdList") List<String> deviceIdList);


    int updateMeasureDataByDeviceAndTime(@Param("deviceId") String deviceId,
                                         @Param("measureTime") LocalDate measureTime,
                                         @Param("measureValue") BigDecimal measureValue,
                                         @Param("avgValue") BigDecimal avgValue,
                                         @Param("incrementValue") BigDecimal incrementValue,
                                         @Param("incrementCost") BigDecimal incrementCost,
                                         @Param("updateUserId") String updateUserId,
                                         @Param("updateTime") LocalDateTime updateTime);

    DeviceMeasureDataDayEntity selectByDeviceIdAndTime(@Param("deviceId") String deviceId,
                                                 @Param("measureTime") LocalDate measureTime);
}
